<template>
  <XcForm ref="formView" :key="tableConfig.length" v-model:visible="visible" :closeReset="true" title="修改校准配置"
    :config="tableConfig" :values="[]" isDialog :colProps="12" :dialogWidth="900" :dialogHeight="500" dialogMaximize
    @open="init" @submit="submit">
    <template #params>
      <NodeTree v-loading="isLoading" class="node-tree" :data="params" />
    </template>
  </XcForm>
</template>

<script lang="ts" setup>
import type { ColumnItem } from "@xc-components/xc-form/types";
import { ref } from "vue";
import type { TreeItem } from "../../../../api/adjust/index.d";
import { getCurrentInstrumneForms, setCalibrationInstruments } from "../../../../api/adjust/index";
import { nodeItem, NodeTree } from "../../../../common/index.js";
import "../../../../common/style.css";
const authStore = {
  calibrationName: "开场校准管理器"
};
const visible = defineModel<boolean>();
const tableConfig = ref<ColumnItem<TreeItem>[]>([{ label: "", prop: "params", type: "slot", slot: "params" }]);
const params = ref<nodeItem[]>([]);
const isLoading = ref(true);

/**
 * @description: 初始化
 * @return {*}
 */
const init = () => {
  getParams();
};

const getParams = async () => {
  isLoading.value = true;
  const { data } = await getCurrentInstrumneForms({}, { calibrationName: authStore.calibrationName });
  isLoading.value = false;
  params.value = data || [];
};
/**
 * @description: 保存
 * @param {*} value
 * @param {*} done
 * @return {*}
 */
const submit = async ({ done }: { value: any; done: (isClose?: boolean) => void }) => {
  try {
    await setCalibrationInstruments({ setform: params.value }, { calibrationName: authStore.calibrationName });
    visible.value = false;
  } finally {
    done();
  }
};
</script>
<style lang="scss" scoped></style>
